package com.zc.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.zc.dao.IPowerDao;
import com.zc.domain.DoubleListData;
import com.zc.domain.FaultItem;
import com.zc.domain.FourPointsItem;
import com.zc.domain.Item;
import com.zc.domain.TwoPointsItem;
import com.zc.service.PowerService;
import com.zc.service.RedisService;

@Controller
public class PowerController {
	@Autowired
	private PowerService powerService;
	@Autowired
	private RedisService redisService;
	
	@RequestMapping(value = "/getSubPower",method = RequestMethod.POST)
    public @ResponseBody List<Item> getSubPower(){       	
		String key="subPowerData";
		List<Item> subPowerData=null;
		if(redisService.hasKey(key)){
			subPowerData=(List<Item>) redisService.get(key);
		}		
		else {
			subPowerData=powerService.getSubPower();
			redisService.set(key, subPowerData);
		}
		return subPowerData;
    }
	
	@RequestMapping(value = "/getMainPower",method = RequestMethod.POST)
    public @ResponseBody List<Item> getMainPower(){       	
		String key="mainPowerData";
		List<Item> mainPowerData=null;
		if(redisService.hasKey(key)){
			mainPowerData=(List<Item>) redisService.get(key);
		}		
		else {
			mainPowerData=powerService.getMainPower();
			redisService.set(key, mainPowerData);
		}
		return mainPowerData;
    }
}
